package pl.com.like.sequoia.dao.bio;

import java.util.Collections;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import pl.com.like.sequoia.dao.GenericDao;
import pl.com.like.sequoia.model.bio.BioObjectHandler;
import pl.com.like.sequoia.model.bio.BioParam;

public class BioParamDao extends GenericDao<BioParam, Long> implements IBioParamDao {

	public BioParamDao() {
		super(BioParam.class);
	}

	@SuppressWarnings("unchecked")
	public List<BioParam> getParamsByObject(BioObjectHandler objHandler) {
		return getCriteria().add(Restrictions.eq("parent", objHandler)).list();
	}

	public List<BioParam> getParamsByObject(Long bioObjectHandlerId) {
		List<BioParam> list = Collections.emptyList();
		if (bioObjectHandlerId != null) {
			Criteria objHandlerCrit = getSession().createCriteria(BioObjectHandler.class);
			BioObjectHandler objHandler = (BioObjectHandler) objHandlerCrit.add(
					Restrictions.eq("id", bioObjectHandlerId)).uniqueResult();
			if (objHandler != null) {
				list = getParamsByObject(objHandler);
			}
		}
		return list;
	}

	public List<BioParam> getParamsByObject(String objName) {
		List<BioParam> list = Collections.emptyList();
		if (objName != null) {
			Criteria objHandlerCrit = getSession().createCriteria(BioObjectHandler.class);
			BioObjectHandler objHandler = (BioObjectHandler) objHandlerCrit.add(Restrictions.eq("id", objName))
					.uniqueResult();
			if (objHandler != null) {
				list = getParamsByObject(objHandler);
			}
		}
		return list;
	}

}
